extends PlayerState

# ===============================================

const DURATION_MAX_BONUS: float = 1000.0
const EASE_REWARD_FACTOR: float = 2.0

# ===============================================

@export var power: float = 70

# ===============================================

var start_shoot_timestamp: int
var shoot_direction: Vector2 = Vector2.ZERO

# ===============================================

func enter() -> void:
	start_shoot_timestamp = Time.get_ticks_msec()
	player.velocity = Vector2.ZERO
	player.animation_player.play("prepare_shoot")


func process(delta: float) -> void:
	shoot_direction += KeyUtils.get_input_vector(player.control_scheme) * delta
	if KeyUtils.is_action_just_released(player.control_scheme, KeyUtils.Action.SHOOT):
		var ease_time: float = (Time.get_ticks_msec() - start_shoot_timestamp) / DURATION_MAX_BONUS
		var bonus: float = ease(clampf(ease_time, 0, 1), EASE_REWARD_FACTOR)
		var shoot_power: float = power * (1 + bonus)
		shoot_direction = shoot_direction.normalized()
		player.ball.shoot.emit(shoot_power * shoot_direction)
		state_transition.emit(self, State.SHOOT)
	
